package bpm.dao.impl.user;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.user.OrgGroup;
import bpm.domain.user.OrgGroupType;
import bpm.domain.user.Privilege;
import bpm.domain.user.Privilege.ResourceScopeType;
import bpm.domain.user.Privilege.ResourceType;
/**
 * 
 * @author ZhaoWangLong Sep 9, 2011
 *
 */
public class PrivilegeRowMapper implements RowMapper {

	public Object mapRow(ResultSet rs, int i) throws SQLException {
		Privilege privilege=new Privilege();
		privilege.setId(rs.getString("ID"));
		OrgGroup role=new OrgGroup();
		role.setId(rs.getString("ROLE_ID"));
		OrgGroupType groupType=new OrgGroupType();
		groupType.setId(rs.getString("ROLE_TYPE"));
		role.setGroupType(groupType);
		privilege.setRole(role);
		ResourceType resourceType=null;
		if(rs.getString("RES_TYPE")!=null&&!"".equals(rs.getString("RES_TYPE")))
			resourceType=ResourceType.valueOf(rs.getString("RES_TYPE"));
		privilege.setResourceType(resourceType);
		privilege.setResourceId(rs.getString("RES_ID"));
		privilege.setResourceScope(rs.getString("RES_SCOPE"));
		ResourceScopeType scopeType=null;
		String st=rs.getString("RES_SCOPE_TYPE");
		if(st!=null&&!"".equals(st))
			scopeType=ResourceScopeType.valueOf(st);
		privilege.setResourceScopeType(scopeType);
		privilege.setConstant("1".equals(rs.getString("CONSTANT"))?true:false);
		privilege.setDirect("1".equals(rs.getString("DIRECT"))?true:false);
		privilege.setDescription(rs.getString("DESCRIPTION"));
		return privilege;
	}

}
